package com.icode.core.model.manage;

import com.icode.core.dto.manager.ContactsDTO;
import com.icode.core.model.AbstractEntity;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-7-14
 * Time: 上午11:20
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "contacts")
public class Contacts extends AbstractEntity {

    @Column(name = "cus_name")
    private String cusName;
    private String area;
    private String gender;
    private String phone;
    private String product;
    private String price;
    private String paid;  //已付金额
    private String remainder; //剩余金额
    private String week;
    @Column(name = "vip_grade")
    @Enumerated(EnumType.STRING)
    private VipGrade vipGrade;

    public Contacts() {
    }

    public Contacts(String cusName, String area, String gender, String phone, String product, String price, String paid, String remainder, String week) {
        this.cusName = cusName;
        this.area = area;
        this.gender = gender;
        this.phone = phone;
        this.product = product;
        this.price = price;
        this.paid = paid;
        this.remainder = remainder;
        this.week = week;
    }

    public void initContacts(ContactsDTO contactsDTO) {
        this.cusName = contactsDTO.getCusName();
        this.area = contactsDTO.getArea();
        this.gender = contactsDTO.getGender();
        this.phone = contactsDTO.getPhone();
        this.product = contactsDTO.getProduct();
        this.price = contactsDTO.getPrice();
        this.paid = contactsDTO.getPaid();
        this.remainder = String.valueOf(isNumber(contactsDTO.getPrice()) - isNumber(contactsDTO.getPaid()));
        this.week = contactsDTO.getWeek();
    }

    public int isNumber(String number) {
        String num = number.replaceAll(",", "");
        return Integer.parseInt(num);
    }

    public String cusName() {
        return cusName;
    }

    public String area() {
        return area;
    }

    public String paid() {
        return paid;
    }

    public String remainder() {
        return remainder;
    }

    public String gender() {
        return gender;
    }

    public String phone() {
        return phone;
    }

    public String product() {
        return product;
    }

    public String price() {
        return price;
    }

    public String week() {
        return week;
    }

    public VipGrade vipGrade() {
        return vipGrade;
    }
}
